﻿@using Aguacongas.TheIdServer.BlazorApp.Pages.User.Components

@page "/user"
@page "/user/{id}"
@inherits EntityModel<Models.User>

@if (Model == null)
{
    <PageLoading />
}
else
{
    <EditForm EditContext="EditContext" OnValidSubmit="HandleValidSubmit">
        <CascadingValue Value="HandleModificationState">
            <div class="row bg-light sticky-top mb-3">
                <div class="col">
                    <h3>@Model.UserName</h3>
                </div>
                <div class="col">
                    <SaveButton />
                    @if (!IsNew)
                    {
                        <DeleteEntityButton EntityId="@Model.Id" DeleteConfirmed="DeleteEntity" />
                        <ExportButton EntityPath="@EntityPath" Request="@ExportRequest" />
                        <CloneButton />
                    }
                </div>
                <div class="col">
                    <Filter CssClass="mt-1" />
                </div>
                <div class="w-100"></div>
                <div class="col">
                    <ul class="list-inline">
                        <li class="list-inline-item">
                            <a href="@(NavigationManager.Uri)#claims" @onclick='() => ScrollTo("claims")' @onclick:preventDefault>@Localizer["claims"]</a>
                        </li>
                        <li class="list-inline-item">
                            <a href="@(NavigationManager.Uri)#roles" @onclick='() => ScrollTo("roles")' @onclick:preventDefault>@Localizer["roles"]</a>
                        </li>
                        <li class="list-inline-item">
                            <a href="@(NavigationManager.Uri)#consents" @onclick='() => ScrollTo("consents")' @onclick:preventDefault>@Localizer["consents"]</a>
                        </li>
                        <li class="list-inline-item">
                            <a href="@(NavigationManager.Uri)#external-logins" @onclick='() => ScrollTo("external-logins")' @onclick:preventDefault>@Localizer["external logins"]</a>
                        </li>
                        <li class="list-inline-item">
                            <a href="@(NavigationManager.Uri)#external-logins-tokens" @onclick='() => ScrollTo("external-logins-tokens")' @onclick:preventDefault>@Localizer["external logins tokens"]</a>
                        </li>
                        <li class="list-inline-item">
                            <a href="@(NavigationManager.Uri)#sessions" @onclick='() => ScrollTo("sessions")' @onclick:preventDefault>@Localizer["sessions"]</a>
                        </li>
                        <li class="list-inline-item">
                            <a href="@(NavigationManager.Uri)#reference-tokens" @onclick='() => ScrollTo("reference-tokens")' @onclick:preventDefault>@Localizer["reference tokens"]</a>
                        </li>
                        <li class="list-inline-item">
                            <a href="@(NavigationManager.Uri)#refresh-tokens" @onclick='() => ScrollTo("refresh-tokens")' @onclick:preventDefault>@Localizer["refresh tokens"]</a>
                        </li>
                        <li class="list-inline-item">
                            <a href="@(NavigationManager.Uri)#ciba-requests" @onclick='() => ScrollTo("ciba-requests")' @onclick:preventDefault>@Localizer["ciba requests"]</a>
                        </li>
                    </ul>
                </div>
                <div class="w-100"></div>
                <FluentValidationValidator />
                <ValidationSummary class="col" />
            </div>
            <div class="entity-details">
                <div class="card mb-3">
                    <div class="card-body">
                        <div class="mb-3 row">
                            <label class="col col-form-label" for="email">
                                @Localizer["user name"]
                            </label>
                            <div class="col-lg-10 col-sm-12">
                                <AuthorizeText Id="name" Placeholder="@Localizer["user name"]" @bind-Value="@Model.UserName" />
                            </div>
                        </div>
                        @if (IsNew)
                        {
                            <div class="mb-3 row">
                                <label class="col col-form-label" for="description">
                                    @Localizer["password"]
                                </label>
                                <div class="col-lg-10 col-sm-12">
                                    <AuthorizeText Id="password" Placeholder="@Localizer["password"]" @bind-Value="@Model.Password" />
                                </div>
                            </div>
                        }
                        <div class="mb-3 row">
                            <label class="col col-form-label" for="email">
                                @Localizer["email"]
                            </label>
                            <div class="col-lg-10 col-sm-12">
                                <AuthorizeText Id="email" Placeholder="@Localizer["email"]" @bind-Value="@Model.Email" />
                                <div>
                                    <AuthorizeCheckbox Name="email-confirmed" Label="@Localizer["email confirmed"]" @bind-Value="@Model.EmailConfirmed" />
                                </div>
                            </div>
                        </div>
                        <div class="mb-3 row">
                            <label class="col col-form-label" for="phone-number">
                                @Localizer["phone number"]
                            </label>
                            <div class="col-lg-10 col-sm-12">
                                <AuthorizeText Id="phone-number" Placeholder="@Localizer["phone number"]" @bind-Value="@Model.PhoneNumber" />
                                <div>
                                    <AuthorizeCheckbox Name="phone-number-confirmed" Label="@Localizer["phone number confirmed"]" @bind-Value="@Model.PhoneNumberConfirmed" />
                                </div>
                            </div>
                        </div>
                        <div class="mb-3 row">
                            <label class="col col-form-label" for="lokoutend">
                                @Localizer["lockout end"]
                            </label>
                            <div class="col-lg-10 col-sm-12">
                                <AuthorizeDate Id="lokoutend" @bind-Value="@Model.LockoutEnd" />
                                <div>
                                    <AuthorizeCheckbox Name="lockout-enabled" Label="@Localizer["lockout enabled"]" @bind-Value="@Model.LockoutEnabled" />
                                </div>
                            </div>
                        </div>
                        <div class="mb-3 row">
                            <label class="col col-form-label">
                            </label>
                            <div class="col-lg-10 col-sm-12">
                                <AuthorizeCheckbox Name="two-factor-enabled" Label="@Localizer["two factor enabled"]" @bind-Value="@Model.TwoFactorEnabled" />
                            </div>
                        </div>
                        <div class="mb-3 row">
                            <label class="col col-form-label" for="access-failed-count">
                                @Localizer["access failed count"]
                            </label>
                            <div class="col-lg-10 col-sm-12">
                                <input id="access-failed-count" type="text" readonly class="form-control-plaintext" value="@Model.AccessFailedCount" />
                            </div>
                        </div>
                    </div>
                </div>
                <div id="claims" class="card mb-3">
                    <div class="card-header">
                        <EntitySubGridTitle Text="@Localizer["Claims"]" Collection="@Model.Claims" CreateModel="CreateClaim" />
                    </div>
                    <div class="card-body">
                        <UserClaims Collection="Model.Claims" />
                    </div>
                </div>
                <div id="roles" class="card mb-3">
                    <div class="card-header">
                        <div class="row">
                            <h5 class="col">@Localizer["Roles"]</h5>
                        </div>
                    </div>
                    <div class="card-body">
                        <UserRoles Model="@Model.Roles" />
                    </div>
                </div>
                <div id="consents" class="card mb-3">
                    <div class="card-header">
                        <div class="row">
                            <h5 class="col">@Localizer["Consents"]</h5>
                        </div>
                    </div>
                    <div class="card-body">
                        <UserConsents Collection="@Model.Consents" />
                    </div>
                </div>
                <div id="external-logins" class="card mb-3">
                    <div class="card-header">
                        <div class="row">
                            <h5 class="col">@Localizer["External logins"]</h5>
                        </div>
                    </div>
                    <div class="card-body">
                        <UserLogins Collection="@Model.Logins" />
                    </div>
                </div>
                <div id="external-logins-tokens" class="card mb-3">
                    <div class="card-header">
                        <div class="row">
                            <h5 class="col">@Localizer["External login tokens"]</h5>
                        </div>
                    </div>
                    <div class="card-body">
                        <UserTokens Collection="@Model.Tokens" />
                    </div>
                </div>
                <div id="sessions" class="card mb-3">
                    <div class="card-header">
                        <div class="row">
                            <h5 class="col">@Localizer["Sessions"]</h5>
                        </div>
                    </div>
                    <div class="card-body">
                        <Sessions Collection="@Model.Sessions" />
                    </div>
                </div>
                <div id="reference-tokens" class="card mb-3">
                    <div class="card-header">
                        <div class="row">
                            <h5 class="col">@Localizer["Reference tokens"]</h5>
                        </div>
                    </div>
                    <div class="card-body">
                        <ReferenceToken Collection="@Model.ReferenceTokens" />
                    </div>
                </div>
                <div id="refresh-tokens" class="card mb-3">
                    <div class="card-header">
                        <div class="row">
                            <h5 class="col">@Localizer["Refresh tokens"]</h5>
                        </div>
                    </div>
                    <div class="card-body">
                        <RefreshToken Collection="@Model.RefreshTokens" />
                    </div>
                </div>
                <div id="ciba-requests" class="card mb-3">
                    <div class="card-header">
                        <div class="row">
                            <h5 class="col">@Localizer["Backchannel login requests"]</h5>
                        </div>
                    </div>
                    <div class="card-body">
                        <BackChannelAuthenticationRequest Collection="@Model.BackChannelAuthenticationRequests" />
                    </div>
                </div>
            </div>
        </CascadingValue>
    </EditForm>
}
